package com.fun.demo.fun;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;

public class ReflectTest {

    private int id1;
    protected int id2;
    public int id3;


    private void fun1(){
        System.out.println(11111111);

    };
    protected void fun2(){
        System.out.println(222222222);
    };
    public void fun3(){
        System.out.println(333333333);
    };

    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InstantiationException, InvocationTargetException {
        HashMap<String, Object> map = new HashMap();
        Class c = Class.forName("com.kayang.ReflectTest");
        Constructor constructor = c.getConstructor();
        Object o = constructor.newInstance();
        ReflectTest f = (ReflectTest)c.newInstance();
        Method method = c.getDeclaredMethod("fun1");
        method.invoke(f);
        System.out.println(o);
        System.out.println(f);
        method.invoke(o);


//        Field f = c.getDeclaredField("id3");
//        f.setAccessible(true);
//       f.setInt(Integer.class, 110);
//        System.out.println("ok");


        /*try {
            Class<?> c = Class.forName("com.kayang.ReflectTest");
            for (Field f : c.getFields()) {

                System.out.println(f.getName());

            }

            System.out.println("1-------------------------");

            for (Field f : c.getDeclaredFields()) {
                System.out.println(f.getName());
            }

            System.out.println("2-------------------------");

            for (Method m : c.getMethods()) {
                System.out.println(m.getName());
            }

            System.out.println("3-------------------------");

            for (Method m : c.getDeclaredMethods()) {
                System.out.println(m.getName());
            }

            c.getEnclosingMethod();


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }*/
    }
}
